package com.lyf.scm.admin.domain.remote.allocationservice.facade;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.lyf.scm.admin.api.dto.EChartsDTO;
import com.lyf.scm.admin.api.dto.SalesPlanDirectlyAccuracyDTO;
import com.lyf.scm.admin.api.dto.SalesPlanDirectlyAccuracyInfoDTO;
import com.lyf.scm.admin.domain.remote.allocationservice.SalesPlanDirectlyAccuracyRemote;
import com.lyf.scm.common.enums.ResponseMsg;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.core.exception.RomeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 直营预测计划_销售计划准确率
 *
 * @author wangchlei
 * @date 2020/08/13
 */
@Service
@Slf4j
public class SalesPlanDirectlyAccuracyFacade {
    @Resource
    private SalesPlanDirectlyAccuracyRemote salesPlanDirectlyAccuracyRemote;


    /**
     * 按条件查询直营预测计划_销售计划准确率(周)
     *
     * @param salesPlanDirectlyAccuracyDTO
     * @return
     */
    public PageInfo<SalesPlanDirectlyAccuracyInfoDTO> listWeekBySelective(SalesPlanDirectlyAccuracyDTO salesPlanDirectlyAccuracyDTO) {
        log.info("按条件查询直营预测计划_销售计划准确率(周)入参:SalesPlanDirectlyAccuracyDTO:{}", JSON.toJSONString(salesPlanDirectlyAccuracyDTO));
        Response<PageInfo<SalesPlanDirectlyAccuracyInfoDTO>> response = salesPlanDirectlyAccuracyRemote.listWeekBySelective(salesPlanDirectlyAccuracyDTO);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    /**
     * 图表数据接口
     *
     * @param salesPlanDirectlyAccuracyDTO
     * @return {@link EChartsDTO}
     **/
    public EChartsDTO listAllByCycles(SalesPlanDirectlyAccuracyDTO salesPlanDirectlyAccuracyDTO) {
        log.info("图表数据接口入参:SalesPlanDirectlyAccuracyDTO:{}", JSON.toJSONString(salesPlanDirectlyAccuracyDTO));
        Response<EChartsDTO> response = salesPlanDirectlyAccuracyRemote.listAllByCycles(salesPlanDirectlyAccuracyDTO);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    public feign.Response export(SalesPlanDirectlyAccuracyDTO salesPlanDirectlyAccuracyDTO, Integer type) {
        log.info("直营预测计划_销售计划准确率导出入参:SalesPlanDirectlyAccuracyDTO:{}", JSON.toJSONString(salesPlanDirectlyAccuracyDTO));
        return salesPlanDirectlyAccuracyRemote.export(salesPlanDirectlyAccuracyDTO, type);
    }

    public void delete(String opSign) {
        log.info("删除直营预测计划_销售计划准确率:{}", JSON.toJSONString(opSign));
        salesPlanDirectlyAccuracyRemote.delete(opSign);
    }
}
